import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:lcapp/api/interface/user_api.dart';
import 'package:lcapp/api/request/response_data.dart';
import 'package:lcapp/config/const_config.dart';
import 'package:lcapp/model/toast/toast.dart';
import 'package:lcapp/widget/asr_app_bar.dart';

class GetMoneySurePage extends StatefulWidget {
  final Map arguments; //0银行卡 1支付宝
  const GetMoneySurePage({Key? key, required this.arguments}) : super(key: key);

  @override
  _GetMoneySurePageState createState() => _GetMoneySurePageState();
}

class _GetMoneySurePageState extends State<GetMoneySurePage> {

  TextEditingController cardController = TextEditingController();
  TextEditingController phoneController = TextEditingController();

  getMoney()async{
    if(cardController.text.trim().isEmpty||phoneController.text.trim().isEmpty){
      showToast("请先输入账号、手机号信息");
      return;
    }
    showLoading();
    Map<String,dynamic> map = {
      'amount':widget.arguments['amount'],
      'phone':phoneController.text.trim(),
      'withdrawType':widget.arguments['type']
    };
    if(widget.arguments['type']==1){
      map['unionpay'] = cardController.text.trim();
    }else{
      map['alipay'] = cardController.text.trim();
    }
    ResponseData res = await UserAPI.minGetMoney(map);
    hideLoading();
    if(res.code==200){
      showToast("提现申请成功!");
      Navigator.of(context).pop();
    }
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AsrAppBar(
        titleText: '确认提现',
        barColor: Colors.white,
        backgroundColor: defaultBarColor,
      ),
      body: SingleChildScrollView(
        child: GestureDetector(
          onTap: (){
            FocusScope.of(context).requestFocus(FocusNode());
          },
          child: Column(
            children: [
              Container(
                height: 100.w,
                // color: Colors.red,
                child: TextField(
                  controller: cardController,
                  maxLines: 1,
                  maxLength: 30,
                  style: TextStyle(
                      fontSize: 34.sp
                  ),
                  decoration:  InputDecoration(
                    contentPadding: EdgeInsets.symmetric(horizontal: 30.w),
                    hintText: widget.arguments['type']==1? "请输入银行卡号":'请输入支付宝账号',
                    hintStyle: TextStyle(
                      color: const Color(0xFF7F7F7F),
                      fontSize: 34.sp,
                      fontWeight: FontWeight.w500,
                    ),
                    counterText: "",
                    border: const OutlineInputBorder(
                      borderSide: BorderSide.none,
                    ),
                    fillColor: Colors.transparent,
                    filled: true,
                  ),
                ),
              ),
              Container(
                height: 0.5,
                color: Color(0xffE9E8E9),
              ),
              Container(
                height: 100.w,
                // color: Colors.red,
                child: TextField(
                  controller: phoneController,
                  maxLines: 1,
                  maxLength: 11,
                  style: TextStyle(
                      fontSize: 34.sp
                  ),
                  keyboardType: TextInputType.phone,
                  decoration:  InputDecoration(
                    contentPadding: EdgeInsets.symmetric(horizontal: 30.w),
                    hintText: "请输入手机号",
                    hintStyle: TextStyle(
                      color: const Color(0xFF7F7F7F),
                      fontSize: 34.sp,
                      fontWeight: FontWeight.w500,
                    ),
                    counterText: "",
                    border: const OutlineInputBorder(
                      borderSide: BorderSide.none,
                    ),
                    fillColor: Colors.transparent,
                    filled: true,
                  ),
                ),
              ),
              Container(
                height: 0.5,
                color: Color(0xffE9E8E9),
              ),
              GestureDetector(
                onTap: (){
                  FocusScope.of(context).requestFocus(FocusNode());
                  getMoney();
                },
                child: Container(
                  margin: EdgeInsets.symmetric(vertical: 80.w),
                  padding: EdgeInsets.symmetric(horizontal: 30.w),
                  child: Container(
                    height: 80.w,
                    width: 1.sw - 60.w,
                    alignment: Alignment.center,
                    decoration: BoxDecoration(
                        color: Color(0xffFA6E28),
                        borderRadius: BorderRadius.circular(80.w)),
                    child: Text(
                      '确认提现',
                      style: TextStyle(
                          color: Colors.white,
                          fontWeight: FontWeight.w600,
                          fontSize: 34.sp),
                    ),
                  ),
                ),
              ),
            ],
          ),
        ),
      ),
    );
  }
}
